<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <textarea v-model="count" @input="add"></textarea>
        <span v-if="count.length <= total">剩余字数:{{residue}}/{{total}}</span>
      </div>
</body>
<script src="Vue.js"></script>
<script>
    // 8. 字数统计  https://www.jq22.com/yanshi3282
   
    let { createApp, ref} = Vue;
  createApp({
    setup() {
      let count = ref('');
      let total = 200;
      let residue = ref(total - count.value.length);
      function add() {
        count.value = count.value.slice(0, total);
        residue.value = total - count.value.length;
      };
      return {
        count,
        residue,
        add,
        total
      };
    }
  }).mount("#app");
</script>
</html>